package com.gxa.park.core.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author Min
 */
public class JsonUtil {
    private static ObjectMapper objectMapper;
    static {
        objectMapper=new ObjectMapper();
    }

    /**
     * 将json字符串转换成对象
     * @param s
     * @param tClass
     * @param <T>
     * @return
     * @throws JsonProcessingException
     */
    public static <T>  T read(String s,Class<T> tClass) throws JsonProcessingException {

        T t = objectMapper.readValue(s, tClass);
        return t;
    }

    /**
     * 将对象转换成json字符串
     * @param o
     * @return
     * @throws JsonProcessingException
     */
    public static String write(Object o) throws JsonProcessingException {
        String jsonString = objectMapper.writeValueAsString(o);
        return jsonString;
    }
}
